package com;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import cn.hutool.core.util.ArrayUtil;

public class TestSort {
	public static void main(String[] args) {
		String[] arrs = new String[]{"a", "b", "c", "d", "e"};
		System.out.println(Arrays.binarySearch(arrs, "d"));
		System.out.println(Arrays.binarySearch(arrs, "d"));
		System.out.println(Arrays.binarySearch(arrs, "d"));
		
		 String[] colums = new String[] { "cuscode", "product", "lotno", "guarantee", "lailiaobox", "boxname", "glassid", "iqctime", "iqcuser", "iqcname", 
        		 "djtime", "djuser",
        		"jbtime", "jbjitai", "jblj", "jbuser", "pgtime", 
        		"pgjitai", "cpress", "ctime", "tpress", "ttime",
        		"pguser",
        		"lhtime","lhwd","lhsj","lhuser",
   			 	"fmtime","fmjitai","fmuser",
        		"pftime", "pfjitai", "pfuser",
        		"dmtime", "dmuser","machineNo",
        		"oqctime", "oqcsc", "oqcjy",
        		"rwtime", "rwuser", "wintime", "winuser", "opertime", "operuser", "lotid", "templateid", "isHolding","outplace",
        		"tuocode","tagname", "tagtime", "taguser", "tagpot","sourceglass", "po", "outpo", "cxtuocode", "ppboxid"};
		 
		 System.out.println(ArrayUtil.indexOf(colums, "lotno"));
        
		
		
		
		List<User> list = new ArrayList<User>();
		list.add(new User("张三", 5, "2021-03-01"));
		list.add(new User("李四", 30, "2021-03-05"));
		list.add(new User("王五", 19, "2021-03-03"));
		list.add(new User("王五", 19, null));
		list.add(new User("陈十七", 17, "2021-03-01")); // 陈十七永远十七岁
		Collections.sort(list, new Comparator<User>() {
			@Override
			public int compare(User u1, User u2) {
				int diff = (u1.getBirth()==null?"":u1.getBirth()).compareTo((u2.getBirth()==null?"":u2.getBirth()));
				if (diff > 0) {
					return 1;
				} else if (diff < 0) {
					return -1;
				}
				return 0; // 相等为0
			}
		}); // 按年龄排序
		System.out.println(list.toString());
		User nwU = new User("陈十七x", 17, "2021-03-01");
		list.add(nwU);
		nwU.setName("XXXXXXXXXXX");
		for(User u : list) {
			System.out.println(u.getName());
		}
	}
}

class User {
	private String name;
	private Integer age;
	private String birth;

	public String getBirth() {
		return birth;
	}

	public void setBirth(String birth) {
		this.birth = birth;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public User(String name, Integer age,String birth) {
		this.name = name;
		this.age = age;
		this.birth = birth;
	}

	public User() {

	}

	@Override
	public String toString() {
		return "User [name=" + name + ", age=" + age + ", birth=" + birth + "]";
	}


	
}